package com.ruoyi.order.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.mapper.CropTypeMapper;
import com.ruoyi.order.mapper.AreaMapper;
import com.ruoyi.order.mapper.GreenhouseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.order.mapper.OrderAllocationMapper;
import com.ruoyi.order.domain.OrderAllocation;
import com.ruoyi.order.service.IOrderAllocationService;

/**
 * 订单分配Service业务层处理
 *
 * @author testlove
 * @date 2021-07-08
 */
@Service
public class OrderAllocationServiceImpl implements IOrderAllocationService
{
    @Autowired
    private OrderAllocationMapper orderAllocationMapper;
    @Autowired
    private AreaMapper areaMapper;
    @Autowired
    private GreenhouseMapper greenhouseMapper;
    @Autowired
    private CropTypeMapper cropTypeMapper;

    /**
     * 查询订单分配
     *
     * @param orderAllocationId 订单分配ID
     * @return 订单分配
     */
    @Override
    public OrderAllocation selectOrderAllocationById(Long orderAllocationId)
    {
        OrderAllocation orderAllocation = orderAllocationMapper.selectOrderAllocationById(orderAllocationId);
        return orderAllocation;
    }

    /**
     * 查询订单分配列表
     *
     * @param orderAllocation 订单分配
     * @return 订单分配
     */
    @Override
    public List<OrderAllocation> selectOrderAllocationList(OrderAllocation orderAllocation)
    {
        List<OrderAllocation> orderAllocations = orderAllocationMapper.selectOrderAllocationList(orderAllocation);
        for (OrderAllocation orderAllocation1 :
                orderAllocations) {
//            orderAllocation1.setArea(areaMapper.selectAreaById(orderAllocation1.getAreaId()).getAreaName());
            orderAllocation1.setCropType(cropTypeMapper.selectCropTypeById(orderAllocation1.getCropTypeId()).getCropType());
            orderAllocation1.setGreenhouse(greenhouseMapper.selectGreenhouseById(orderAllocation1.getGreenhouseId()).getGreenhouseName());
            orderAllocation1.setArea(areaMapper.selectAreaById(orderAllocation1.getAreaId()).getAreaName());
        }
        return orderAllocations;
    }

    @Override
    public List<Integer> selectOrderAllocationListId() {
        return orderAllocationMapper.selectOrderAllocationListId();
    }

    /**
     * 新增订单分配
     *
     * @param orderAllocation 订单分配
     * @return 结果
     */
    @Override
    public int insertOrderAllocation(OrderAllocation orderAllocation)
    {
        orderAllocation.setCreateTime(DateUtils.getNowDate());
        return orderAllocationMapper.insertOrderAllocation(orderAllocation);
    }

    /**
     * 修改订单分配
     *
     * @param orderAllocation 订单分配
     * @return 结果
     */
    @Override
    public int updateOrderAllocation(OrderAllocation orderAllocation)
    {
        orderAllocation.setUpdateTime(DateUtils.getNowDate());
        return orderAllocationMapper.updateOrderAllocation(orderAllocation);
    }

    /**
     * 批量删除订单分配
     *
     * @param orderAllocationIds 需要删除的订单分配ID
     * @return 结果
     */
    @Override
    public int deleteOrderAllocationByIds(Long[] orderAllocationIds)
    {
        return orderAllocationMapper.deleteOrderAllocationByIds(orderAllocationIds);
    }

    /**
     * 删除订单分配信息
     *
     * @param orderAllocationId 订单分配ID
     * @return 结果
     */
    @Override
    public int deleteOrderAllocationById(Long orderAllocationId)
    {
        return orderAllocationMapper.deleteOrderAllocationById(orderAllocationId);
    }
}
